import request from '@/utils/request'
// 统一前缀
var prefix = '/userService'

// 条件查询用户
export function lookAllUser(user) {
  return request({
    url: `${prefix}/user/list`,
    method: 'GET',
    params: user,
  })
}

// 用户登录
export function login(data) {
  return request({
    url: `${prefix}/user/login`,
    method: 'post',
    params: data,
  })
}

// 修改用户
export function updateUser(user) {
  return request({
    url: `${prefix}/user`,
    data: user,
    method: 'PUT',
  })
}
// 修改手机号
export function updatePhone(data) {
  return request({
    url: `${prefix}/user/phone`,
    method: 'PUT',
    data: data,
  })
}

// 修改密码
export function updatePassword(user) {
  return request({
    url: `${prefix}/user/password`,
    data: user,
    method: 'PUT',
  })
}

// 获取当前用户信息
export function getInfo(token) {
  return request({
    url: `${prefix}/user/info`,
    method: 'get',
    params: { token: token },
  })
}

// 获取验证码
export function getCaptcha(type) {
  return request({
    url: `${prefix}/captcha/captcha`,
    params: { type: type },
    method: 'GET',
  })
}

// 验证验证码
export function checkCaptcha(uid, code) {
  return request({
    url: `${prefix}/captcha/verify`,
    params: { uuid: uid, code: code },
    method: 'POST',
  })
}

// 上传头像
export function uploadAvatar(uid, fid) {
  return request({
    url: `${prefix}/user/avatar`,
    params: { userId: uid, avatarId: fid },
    method: 'POST',
  })
}

// 获取手机验证码
export function getPhoneCode(phone) {
  return request({
    url: `${prefix}/user/phoneCode`,
    params: { phone: phone },
    method: 'GET',
  })
}

// 校验手机验证码
export function checkPhoneCode(phone, code) {
  return request({
    url: `${prefix}/user/checkPhoneCode`,
    params: { phone: phone, code: code },
    method: 'POST',
  })
}

// 退出登录
export function logout(token) {
  return request({
    url: `${prefix}/user/logout`,
    method: 'post',
    params: { token: token },
  })
}
